<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Rep\SpecificationRep;
use Illuminate\Http\Request;

class Specification extends Controller
{
    //规格管理
    protected $rep;

    public function __construct(Request $request)
    {
        $this->rep = new SpecificationRep();
    }

    /**
     * 获取产品规格列表
     * @param Request $request
     */
    public function getSpecificationList(Request $request){
        $params = $request->all();
        $data = $this->rep->getSpecificationListRep($params);
        return re(0,$data,'success');
    }

    /**
     * 关联规格
     * @param Request $request
     */
    public function createSpecification(Request $request){
        $params = $request->all();
        $data = $this->rep->createSpecificationRep($params);
        return re($data['code'],$data['data']);
    }
    //规格管理添加规格
    public function addSpecification(Request $request){
        $params = $request->all();
        $data = $this->rep->addSpecificationRep($params);
        return re(0,$data);
    }
    public function deleteSpecification(Request $request){
        $params = $request->all();
        $data = $this->rep->deleteSpecificationRep($params);
        return re(0);
    }

    /**
     * 删除规格关联
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delSpecification(Request $request){
        $params = $request->all();
        $data = $this->rep->delSpecificationRep($params);
        return re(0);
    }

    /**
     * 通过规格设置工种价格
     */
    public function setJobTypePriceBySpecificationId(Request $request){

        $params = $request->all();
        //p($params);
        $data = $this->rep->setJobTypePriceBySpecificationIdRep($params);
        return re(0,$data,'success');
    }

    /**
     * 获取规格工种价格
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getJobTypePriceBySpecificationId(Request $request){
        $params = $request->all();
        $data = $this->rep->getJobTypePriceBySpecificationIdRep($params);
        return re(0,$data,'success');
    }

    /**
     * 批量设置工种价格
     */
    public function batchSetJobTypePrice(Request $request){
        $params = $request->all();
        $data = $this->rep->batchSetJobTypePriceRep($params);
        return re(0,$data,'success');
    }

    /**
     * 编辑规格
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function updateSpecification(Request $request){
        $params = $request->all();
        $data = $this->rep->updateSpecificationRep($params);
        return re(0,$data,'success');
    }

    public function getSameJobTypeListProductList(Request $request){
        $params = $request->all();
        $data = $this->rep->getSameJobTypeListProductListRep($params);
        return re(0,$data,'success');
    }
}
